{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "888d1cd8",
   "metadata": {},
   "source": [
    "# 本周学习内容\n",
    "20211104\n",
    "[参考文档](http://python.org/doc)\n",
    "[许老师博客](https://www.cnblogs.com/xuzhichao)\n",
    "## 1.啤酒歌谣项目详解\n",
    "\n",
    "## 2.用户输入\n",
    "\n",
    "## 3.while循环\n",
    "\n",
    "## 4.列表的引入"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d1f9db4d",
   "metadata": {},
   "source": [
    ">1.啤酒歌谣解读"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "ff6d270f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "99 青岛s 在啤酒柜中\n",
      "99 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "98 青岛s 在啤酒柜中\n",
      "98 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "97 青岛s 在啤酒柜中\n",
      "97 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "96 青岛s 在啤酒柜中\n",
      "96 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "95 青岛s 在啤酒柜中\n",
      "95 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "94 青岛s 在啤酒柜中\n",
      "94 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "93 青岛s 在啤酒柜中\n",
      "93 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "92 青岛s 在啤酒柜中\n",
      "92 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "91 青岛s 在啤酒柜中\n",
      "91 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "90 青岛s 在啤酒柜中\n",
      "90 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "89 青岛s 在啤酒柜中\n",
      "89 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "88 青岛s 在啤酒柜中\n",
      "88 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "87 青岛s 在啤酒柜中\n",
      "87 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "86 青岛s 在啤酒柜中\n",
      "86 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "85 青岛s 在啤酒柜中\n",
      "85 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "84 青岛s 在啤酒柜中\n",
      "84 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "83 青岛s 在啤酒柜中\n",
      "83 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "82 青岛s 在啤酒柜中\n",
      "82 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "81 青岛s 在啤酒柜中\n",
      "81 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "80 青岛s 在啤酒柜中\n",
      "80 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "79 青岛s 在啤酒柜中\n",
      "79 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "78 青岛s 在啤酒柜中\n",
      "78 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "77 青岛s 在啤酒柜中\n",
      "77 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "76 青岛s 在啤酒柜中\n",
      "76 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "75 青岛s 在啤酒柜中\n",
      "75 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "74 青岛s 在啤酒柜中\n",
      "74 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "73 青岛s 在啤酒柜中\n",
      "73 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "72 青岛s 在啤酒柜中\n",
      "72 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "71 青岛s 在啤酒柜中\n",
      "71 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "70 青岛s 在啤酒柜中\n",
      "70 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "69 青岛s 在啤酒柜中\n",
      "69 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "68 青岛s 在啤酒柜中\n",
      "68 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "67 青岛s 在啤酒柜中\n",
      "67 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "66 青岛s 在啤酒柜中\n",
      "66 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "65 青岛s 在啤酒柜中\n",
      "65 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "64 青岛s 在啤酒柜中\n",
      "64 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "63 青岛s 在啤酒柜中\n",
      "63 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "62 青岛s 在啤酒柜中\n",
      "62 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "61 青岛s 在啤酒柜中\n",
      "61 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "60 青岛s 在啤酒柜中\n",
      "60 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "59 青岛s 在啤酒柜中\n",
      "59 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "58 青岛s 在啤酒柜中\n",
      "58 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "57 青岛s 在啤酒柜中\n",
      "57 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "56 青岛s 在啤酒柜中\n",
      "56 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "55 青岛s 在啤酒柜中\n",
      "55 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "54 青岛s 在啤酒柜中\n",
      "54 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "53 青岛s 在啤酒柜中\n",
      "53 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "52 青岛s 在啤酒柜中\n",
      "52 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "51 青岛s 在啤酒柜中\n",
      "51 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "50 青岛s 在啤酒柜中\n",
      "50 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "49 青岛s 在啤酒柜中\n",
      "49 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "48 青岛s 在啤酒柜中\n",
      "48 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "47 青岛s 在啤酒柜中\n",
      "47 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "46 青岛s 在啤酒柜中\n",
      "46 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "45 青岛s 在啤酒柜中\n",
      "45 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "44 青岛s 在啤酒柜中\n",
      "44 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "43 青岛s 在啤酒柜中\n",
      "43 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "42 青岛s 在啤酒柜中\n",
      "42 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "41 青岛s 在啤酒柜中\n",
      "41 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "40 青岛s 在啤酒柜中\n",
      "40 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "39 青岛s 在啤酒柜中\n",
      "39 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "38 青岛s 在啤酒柜中\n",
      "38 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "37 青岛s 在啤酒柜中\n",
      "37 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "36 青岛s 在啤酒柜中\n",
      "36 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "35 青岛s 在啤酒柜中\n",
      "35 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "34 青岛s 在啤酒柜中\n",
      "34 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "33 青岛s 在啤酒柜中\n",
      "33 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "32 青岛s 在啤酒柜中\n",
      "32 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "31 青岛s 在啤酒柜中\n",
      "31 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "30 青岛s 在啤酒柜中\n",
      "30 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "29 青岛s 在啤酒柜中\n",
      "29 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "28 青岛s 在啤酒柜中\n",
      "28 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "27 青岛s 在啤酒柜中\n",
      "27 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "26 青岛s 在啤酒柜中\n",
      "26 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "25 青岛s 在啤酒柜中\n",
      "25 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "24 青岛s 在啤酒柜中\n",
      "24 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "23 青岛s 在啤酒柜中\n",
      "23 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "22 青岛s 在啤酒柜中\n",
      "22 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "21 青岛s 在啤酒柜中\n",
      "21 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "20 青岛s 在啤酒柜中\n",
      "20 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "19 青岛s 在啤酒柜中\n",
      "19 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "18 青岛s 在啤酒柜中\n",
      "18 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "17 青岛s 在啤酒柜中\n",
      "17 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "16 青岛s 在啤酒柜中\n",
      "16 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "15 青岛s 在啤酒柜中\n",
      "15 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "14 青岛s 在啤酒柜中\n",
      "14 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "13 青岛s 在啤酒柜中\n",
      "13 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "12 青岛s 在啤酒柜中\n",
      "12 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "11 青岛s 在啤酒柜中\n",
      "11 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "10 青岛s 在啤酒柜中\n",
      "10 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "9 青岛s 在啤酒柜中\n",
      "9 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "8 青岛s 在啤酒柜中\n",
      "8 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "7 青岛s 在啤酒柜中\n",
      "7 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "6 青岛s 在啤酒柜中\n",
      "6 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "5 青岛s 在啤酒柜中\n",
      "5 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "4 青岛s 在啤酒柜中\n",
      "4 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "3 青岛s 在啤酒柜中\n",
      "3 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "2 青岛s 在啤酒柜中\n",
      "2 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "1 青岛s 在啤酒柜中\n",
      "1 瓶 青岛s\n",
      "可以拿一瓶\n",
      "给我拿一瓶来\n",
      "没有啤酒可以拿走了，今日卖完了\n"
     ]
    },
    {
     "ename": "NameError",
     "evalue": "name 'new_num' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-1-eee410d53fc9>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m     10\u001b[0m \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     11\u001b[0m     \u001b[0mnew_num\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mbeer_num\u001b[0m \u001b[1;33m-\u001b[0m \u001b[1;36m1\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 12\u001b[1;33m \u001b[1;32mif\u001b[0m \u001b[0mnew_num\u001b[0m \u001b[1;33m==\u001b[0m \u001b[1;36m1\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m     13\u001b[0m     \u001b[0mword\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;34m\"青岛\"\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     14\u001b[0m     \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mnew_num\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mword\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"在啤酒柜中\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mNameError\u001b[0m: name 'new_num' is not defined"
     ]
    }
   ],
   "source": [
    "word = \"青岛s\"\n",
    "#循环，for 一般和range使用，range 决定了循环的次数\n",
    "for beer_num in range(99, 0, -1):\n",
    "    print(beer_num, word, \"在啤酒柜中\")\n",
    "    print(beer_num,\"瓶\", word,)\n",
    "    print(\"可以拿一瓶\")\n",
    "    print(\"给我拿一瓶来\")\n",
    "if beer_num == 1:\n",
    "    print(\"没有啤酒可以拿走了，今日卖完了\")\n",
    "else:\n",
    "    new_num = beer_num - 1\n",
    "if new_num == 1:\n",
    "    word = \"青岛\"\n",
    "    print(new_num, word, \"在啤酒柜中\")\n",
    "    print()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "bf3f9990",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function print in module builtins:\n",
      "\n",
      "print(...)\n",
      "    print(value, ..., sep=' ', end='\\n', file=sys.stdout, flush=False)\n",
      "    \n",
      "    Prints the values to a stream, or to sys.stdout by default.\n",
      "    Optional keyword arguments:\n",
      "    file:  a file-like object (stream); defaults to the current sys.stdout.\n",
      "    sep:   string inserted between values, default a space.\n",
      "    end:   string appended after the last value, default a newline.\n",
      "    flush: whether to forcibly flush the stream.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(print)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "84ef6974",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Zhang zefeng\n",
      "Zhangzefeng\n"
     ]
    }
   ],
   "source": [
    "#区别\n",
    "print(\"Zhang\",\"zefeng\")\n",
    "print(\"Zhang\"+\"zefeng\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "26dc1949",
   "metadata": {},
   "source": [
    ">2.用户输入（input）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "ba3343bb",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入你的账号：110\n"
     ]
    }
   ],
   "source": [
    "username = input(\"请输入你的账号：\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "1f0d4659",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "110\n",
      "<class 'str'>\n"
     ]
    }
   ],
   "source": [
    "print(username)\n",
    "print(type(username))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "1bed351a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'110'"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "username"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a7975c80",
   "metadata": {},
   "source": [
    "# 2.1 input 实践 ：用户登录"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "7bf04ba4",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入你的账号：ALEX\n",
      "请输入你的密码：123456\n",
      "welcome\n"
     ]
    }
   ],
   "source": [
    "# 1.首先：数据库信息有账号和密码\n",
    "username_data = \"ALEX\"\n",
    "password_data = \"123456\"\n",
    "\n",
    "# 2.用户登录：\n",
    "\n",
    "username = input(\"请输入你的账号：\")\n",
    "if username_data == username:\n",
    "    # 账号存在,判断密码\n",
    "    password = input(\"请输入你的密码：\")\n",
    "    if password_data == password:\n",
    "        print(\"welcome\")\n",
    "    # 账号正确，但密码不正确\n",
    "    else:\n",
    "        print(\"您输入但密码不正确！\")\n",
    "else:\n",
    "    print(\"您输入的账号不存在\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "3fab056b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入你的账号：alex\n",
      "请输入你的密码：123\n",
      "请输入你的账号：ALEX\n",
      "请输入你的密码：123456\n"
     ]
    },
    {
     "ename": "KeyboardInterrupt",
     "evalue": "Interrupted by user",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mKeyboardInterrupt\u001b[0m                         Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-18-cf18de961086>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m      6\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      7\u001b[0m \u001b[1;32mwhile\u001b[0m \u001b[1;32mTrue\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 8\u001b[1;33m     \u001b[0musername\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0minput\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"请输入你的账号：\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m      9\u001b[0m     \u001b[0mpassword\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0minput\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"请输入你的密码：\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     10\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mD:\\python\\lib\\site-packages\\ipykernel\\kernelbase.py\u001b[0m in \u001b[0;36mraw_input\u001b[1;34m(self, prompt)\u001b[0m\n\u001b[0;32m    858\u001b[0m                 \u001b[1;34m\"raw_input was called, but this frontend does not support input requests.\"\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    859\u001b[0m             )\n\u001b[1;32m--> 860\u001b[1;33m         return self._input_request(str(prompt),\n\u001b[0m\u001b[0;32m    861\u001b[0m             \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_parent_ident\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    862\u001b[0m             \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_parent_header\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mD:\\python\\lib\\site-packages\\ipykernel\\kernelbase.py\u001b[0m in \u001b[0;36m_input_request\u001b[1;34m(self, prompt, ident, parent, password)\u001b[0m\n\u001b[0;32m    902\u001b[0m             \u001b[1;32mexcept\u001b[0m \u001b[0mKeyboardInterrupt\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    903\u001b[0m                 \u001b[1;31m# re-raise KeyboardInterrupt, to truncate traceback\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 904\u001b[1;33m                 \u001b[1;32mraise\u001b[0m \u001b[0mKeyboardInterrupt\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"Interrupted by user\"\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;32mfrom\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    905\u001b[0m             \u001b[1;32mexcept\u001b[0m \u001b[0mException\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0me\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    906\u001b[0m                 \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mlog\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mwarning\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"Invalid Message:\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mexc_info\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;32mTrue\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mKeyboardInterrupt\u001b[0m: Interrupted by user"
     ]
    }
   ],
   "source": [
    "# 1.首先：数据库信息有账号和密码\n",
    "username_data = \"ALEX\"\n",
    "password_data = \"123456\"\n",
    "\n",
    "# 2.用户登录：\n",
    "\n",
    "while True:\n",
    "    username = input(\"请输入你的账号：\")\n",
    "    password = input(\"请输入你的密码：\")\n",
    "\n",
    "if username_data == username:\n",
    "    if password_data == password:\n",
    "        print(\"welcome\",username)\n",
    "        # 使用 break 结束循环\n",
    "        break\n",
    "    else:\n",
    "        print(\"您输入的账号不存在或密码不正确，请重新输入,还有3次输入机会，否则5分钟后来尝试。\")\n",
    "else:\n",
    "    print(\"您输入的账号不存在或密码不正确，请重新输入\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "0460bd68",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入你的账号：\n",
      "请输入你的密码：\n",
      "您输入的账号不存在或密码不正确~，请重新输入~,您还有 2 次输入当机会，否则5分钟后再来尝试~~\n",
      "请输入你的账号：Alex\n",
      "请输入你的密码：123456\n",
      "欢迎 Alex 使用~\n"
     ]
    }
   ],
   "source": [
    "import time\n",
    "username_data = \"Alex\"\n",
    "password_data = \"123456\"\n",
    "count = 3\n",
    "while True:\n",
    "    count -= 1  #等价于count = count-1\n",
    "    username = input(\"请输入你的账号：\")\n",
    "    password = input(\"请输入你的密码：\")\n",
    "    if username_data == username:\n",
    "        if password_data == password:\n",
    "            print(\"欢迎\",username,\"使用~\")\n",
    "            break\n",
    "        else:\n",
    "                if count == 0:\n",
    "                    print(\"5分钟后再来尝试\")\n",
    "                    time.sleep(5)\n",
    "                    count=3\n",
    "                else:\n",
    "                        print(\"您输入的账号不存在或密码不正确~，请重新输入~,您还有\",count,\"次输入当机会，否则5分钟后再来尝试~~~\")\n",
    "    else:\n",
    "        if count==0:\n",
    "            print(\"5分钟后再来尝试\")\n",
    "            time.sleep(5)\n",
    "            count=3\n",
    "        else:\n",
    "                                print(\"您输入的账号不存在或密码不正确~，请重新输入~,您还有\",count,\"次输入当机会，否则5分钟后再来尝试~~\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d50c6e19",
   "metadata": {},
   "source": [
    "# while 循环\n",
    "> 1.while True:  无限循环,当我们不确定循环次数时，一定要想到<font style = \"color:red\">**while True**</font>\n",
    "> 2.break 跳出循环： 当符合某条件时，结束循环。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "b83c8bb1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "你是风儿，我是沙，缠缠绵绵。 1\n",
      "你是风儿，我是沙，缠缠绵绵。 2\n",
      "你是风儿，我是沙，缠缠绵绵。 3\n",
      "你是风儿，我是沙，缠缠绵绵。 4\n",
      "你是风儿，我是沙，缠缠绵绵。 5\n",
      "你是风儿，我是沙，缠缠绵绵。 6\n",
      "你是风儿，我是沙，缠缠绵绵。 7\n",
      "你是风儿，我是沙，缠缠绵绵。 8\n",
      "你是风儿，我是沙，缠缠绵绵。 9\n",
      "你是风儿，我是沙，缠缠绵绵。 10\n",
      "你是风儿，我是沙，缠缠绵绵。 11\n",
      "你是风儿，我是沙，缠缠绵绵。 12\n",
      "你是风儿，我是沙，缠缠绵绵。 13\n",
      "你是风儿，我是沙，缠缠绵绵。 14\n",
      "你是风儿，我是沙，缠缠绵绵。 15\n",
      "你是风儿，我是沙，缠缠绵绵。 16\n",
      "你是风儿，我是沙，缠缠绵绵。 17\n",
      "你是风儿，我是沙，缠缠绵绵。 18\n",
      "你是风儿，我是沙，缠缠绵绵。 19\n",
      "你是风儿，我是沙，缠缠绵绵。 20\n",
      "你是风儿，我是沙，缠缠绵绵。 21\n",
      "你是风儿，我是沙，缠缠绵绵。 22\n",
      "你是风儿，我是沙，缠缠绵绵。 23\n",
      "你是风儿，我是沙，缠缠绵绵。 24\n",
      "你是风儿，我是沙，缠缠绵绵。 25\n",
      "你是风儿，我是沙，缠缠绵绵。 26\n",
      "你是风儿，我是沙，缠缠绵绵。 27\n",
      "你是风儿，我是沙，缠缠绵绵。 28\n",
      "你是风儿，我是沙，缠缠绵绵。 29\n",
      "你是风儿，我是沙，缠缠绵绵。 30\n",
      "你是风儿，我是沙，缠缠绵绵。 31\n",
      "你是风儿，我是沙，缠缠绵绵。 32\n",
      "你是风儿，我是沙，缠缠绵绵。 33\n",
      "你是风儿，我是沙，缠缠绵绵。 34\n",
      "你是风儿，我是沙，缠缠绵绵。 35\n",
      "你是风儿，我是沙，缠缠绵绵。 36\n",
      "你是风儿，我是沙，缠缠绵绵。 37\n",
      "你是风儿，我是沙，缠缠绵绵。 38\n",
      "你是风儿，我是沙，缠缠绵绵。 39\n",
      "你是风儿，我是沙，缠缠绵绵。 40\n",
      "你是风儿，我是沙，缠缠绵绵。 41\n",
      "你是风儿，我是沙，缠缠绵绵。 42\n",
      "你是风儿，我是沙，缠缠绵绵。 43\n",
      "你是风儿，我是沙，缠缠绵绵。 44\n",
      "你是风儿，我是沙，缠缠绵绵。 45\n",
      "你是风儿，我是沙，缠缠绵绵。 46\n",
      "你是风儿，我是沙，缠缠绵绵。 47\n",
      "你是风儿，我是沙，缠缠绵绵。 48\n",
      "你是风儿，我是沙，缠缠绵绵。 49\n",
      "你是风儿，我是沙，缠缠绵绵。 50\n",
      "你是风儿，我是沙，缠缠绵绵。 51\n",
      "你是风儿，我是沙，缠缠绵绵。 52\n",
      "你是风儿，我是沙，缠缠绵绵。 53\n",
      "你是风儿，我是沙，缠缠绵绵。 54\n",
      "你是风儿，我是沙，缠缠绵绵。 55\n",
      "你是风儿，我是沙，缠缠绵绵。 56\n",
      "你是风儿，我是沙，缠缠绵绵。 57\n",
      "你是风儿，我是沙，缠缠绵绵。 58\n",
      "你是风儿，我是沙，缠缠绵绵。 59\n",
      "你是风儿，我是沙，缠缠绵绵。 60\n",
      "你是风儿，我是沙，缠缠绵绵。 61\n",
      "你是风儿，我是沙，缠缠绵绵。 62\n",
      "你是风儿，我是沙，缠缠绵绵。 63\n",
      "你是风儿，我是沙，缠缠绵绵。 64\n",
      "你是风儿，我是沙，缠缠绵绵。 65\n",
      "你是风儿，我是沙，缠缠绵绵。 66\n",
      "你是风儿，我是沙，缠缠绵绵。 67\n",
      "你是风儿，我是沙，缠缠绵绵。 68\n",
      "你是风儿，我是沙，缠缠绵绵。 69\n",
      "你是风儿，我是沙，缠缠绵绵。 70\n",
      "你是风儿，我是沙，缠缠绵绵。 71\n",
      "你是风儿，我是沙，缠缠绵绵。 72\n",
      "你是风儿，我是沙，缠缠绵绵。 73\n",
      "你是风儿，我是沙，缠缠绵绵。 74\n",
      "你是风儿，我是沙，缠缠绵绵。 75\n",
      "你是风儿，我是沙，缠缠绵绵。 76\n",
      "你是风儿，我是沙，缠缠绵绵。 77\n",
      "你是风儿，我是沙，缠缠绵绵。 78\n",
      "你是风儿，我是沙，缠缠绵绵。 79\n",
      "你是风儿，我是沙，缠缠绵绵。 80\n",
      "你是风儿，我是沙，缠缠绵绵。 81\n",
      "你是风儿，我是沙，缠缠绵绵。 82\n",
      "你是风儿，我是沙，缠缠绵绵。 83\n",
      "你是风儿，我是沙，缠缠绵绵。 84\n",
      "你是风儿，我是沙，缠缠绵绵。 85\n",
      "你是风儿，我是沙，缠缠绵绵。 86\n",
      "你是风儿，我是沙，缠缠绵绵。 87\n",
      "你是风儿，我是沙，缠缠绵绵。 88\n",
      "你是风儿，我是沙，缠缠绵绵。 89\n",
      "你是风儿，我是沙，缠缠绵绵。 90\n",
      "你是风儿，我是沙，缠缠绵绵。 91\n",
      "你是风儿，我是沙，缠缠绵绵。 92\n",
      "你是风儿，我是沙，缠缠绵绵。 93\n",
      "你是风儿，我是沙，缠缠绵绵。 94\n",
      "你是风儿，我是沙，缠缠绵绵。 95\n",
      "你是风儿，我是沙，缠缠绵绵。 96\n",
      "你是风儿，我是沙，缠缠绵绵。 97\n",
      "你是风儿，我是沙，缠缠绵绵。 98\n",
      "你是风儿，我是沙，缠缠绵绵。 99\n",
      "你是风儿，我是沙，缠缠绵绵。 100\n"
     ]
    }
   ],
   "source": [
    "count = 0\n",
    "while True:\n",
    "    count = count+1\n",
    "    print(\"你是风儿，我是沙，缠缠绵绵。\",count)\n",
    "    if count==100:\n",
    "        break"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ddc16e84",
   "metadata": {},
   "source": [
    "# 列表的引入\n",
    "> 1.[什么是列表](https://docs.python.org/3/tutorial/introduction.html#lists)\n",
    "> 2.列表的形式\n",
    "> 3.列表也是[序列]()数据类型\n",
    ">> 1.序列也是有顺序的(可以用索引index取值)\n",
    ">> 2.序列可以切片，切完仍是一个列表"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "4801126f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 4, 9, 16, 25]\n",
      "<class 'list'>\n"
     ]
    }
   ],
   "source": [
    "squares = [1, 4, 9, 16, 25]\n",
    "print(squares)\n",
    "print(type(squares))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "04217bd7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Alex'"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#思考：用户账号数据不止一个，那么想储存怎么办？\n",
    "username_database = \"Alex,zhichao,xiaoming,jack\"\n",
    "username_database[:4]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "c269624d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Alex'"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "username_database_list = [\"Alex\",\"zhichao\",\"xiaoming\",\"Jack\"]\n",
    "username_database_list[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "df227bdd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'zhichao'"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "username_database_list[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "1f3de6a4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Alex', 'zhichao']"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "username_database_list[0:2]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5af7741f",
   "metadata": {},
   "source": [
    "# 2.2占位符和字符串格式化\n",
    "> 1.请同学们实践 4、用户输入 %s占位符打印用户信息"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "73a44bfb",
   "metadata": {},
   "source": [
    ">  \"\"\" 被注释内容 \"\"\"  还可以打印变量"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "ed95b9aa",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "import random\n",
      "wait_time = random.randint(1,60)\n",
      "print(wait_time)\n",
      "\n",
      "word = \"bottles\"\n",
      "print(word)\n",
      "\n"
     ]
    }
   ],
   "source": [
    "test1 ='''\n",
    "import random\n",
    "wait_time = random.randint(1,60)\n",
    "print(wait_time)\n",
    "\n",
    "word = \"bottles\"\n",
    "print(word)\n",
    "'''\n",
    "print(test1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "14099419",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "42972fec",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "name:zhangzefeng\n",
      "age:19\n",
      "job:student\n",
      "salary:0\n",
      "-------INFO OF zhangzefeng -------\n",
      "Name:zhangzefeng\n",
      "Age:19\n",
      "Job:student\n",
      "Salary:0\n",
      "\n"
     ]
    }
   ],
   "source": [
    "name = input(\"name:\")\n",
    "age = input(\"age:\")\n",
    "job = input(\"job:\")\n",
    "salary = input(\"salary:\")\n",
    "\n",
    "info = '''-------INFO OF %s -------\n",
    "Name:%s\n",
    "Age:%s\n",
    "Job:%s\n",
    "Salary:%s\n",
    "'''% (name,name,age,job,salary)\n",
    "\n",
    "print(info)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f1c59c17",
   "metadata": {},
   "source": [
    "> 2 . 请同学们实践 4、用户输入 .format()打印用户信息"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "5d2bc21e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "-------INFO OF zhangzefeng -------\n",
      "Name:zhangzefeng\n",
      "Age:19\n",
      "Job:student\n",
      "Salary:0\n",
      "\n"
     ]
    }
   ],
   "source": [
    "info2 =  '''-------INFO OF {_name} -------\n",
    "Name:{_name}\n",
    "Age:{_age}\n",
    "Job:{_job}\n",
    "Salary:{_salary}\n",
    "'''.format(_name=name,\n",
    "           _age=age,\n",
    "           _job=job,\n",
    "           _salary=salary)\n",
    "print(info2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "fcbb6996",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "name:zhang\n",
      "age:19\n",
      "job:stu\n",
      "salary:0\n",
      "-------INFO OF zhang -------\n",
      "Name:zhang\n",
      "Age:19\n",
      "Job:stu\n",
      "Salary:0\n",
      "\n"
     ]
    }
   ],
   "source": [
    "name = input(\"name:\")\n",
    "age = input(\"age:\")\n",
    "job = input(\"job:\")\n",
    "salary = input(\"salary:\")\n",
    "\n",
    "info = '''-------INFO OF %s -------\n",
    "Name:%s\n",
    "Age:%s\n",
    "Job:%s\n",
    "Salary:%s\n",
    "'''% (name,name,age,job,salary)\n",
    "\n",
    "print(info)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "234fee56",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "name:z\n",
      "age:19\n",
      "job:stu\n",
      "salary:0\n",
      "-------INFO OF z -------\n",
      "Name:z\n",
      "Age:19\n",
      "Job:stu\n",
      "Salary:0\n",
      "\n"
     ]
    }
   ],
   "source": [
    "name = input(\"name:\")\n",
    "age = int(input(\"age:\"))  #注意！ python中默认所有的输入均为string\n",
    "job = input(\"job:\")\n",
    "salary = int(input(\"salary:\"))\n",
    "\n",
    "info = '''-------INFO OF %s -------\n",
    "Name:%s\n",
    "Age:%d\n",
    "Job:%s\n",
    "Salary:%d\n",
    "'''% (name,name,age,job,salary)\n",
    "\n",
    "print(info)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "414dcc67",
   "metadata": {},
   "source": [
    ">format()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "220d6099",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "-------INFO OF z -------\n",
      "Name:z\n",
      "Age:19\n",
      "Job:stu\n",
      "Salary:0\n",
      "\n"
     ]
    }
   ],
   "source": [
    "info2 =  '''-------INFO OF {_name} -------\n",
    "Name:{_name}\n",
    "Age:{_age}\n",
    "Job:{_job}\n",
    "Salary:{_salary}\n",
    "'''.format(_name=name,\n",
    "           _age=age,\n",
    "           _job=job,\n",
    "           _salary=salary)\n",
    "print(info2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "b0967791",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "H\n",
      "i\n",
      "!\n"
     ]
    }
   ],
   "source": [
    "for ch in \"Hi!\":\n",
    "      print(ch)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "ca89614a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "i\n",
      "a\n"
     ]
    }
   ],
   "source": [
    "vowels = ['a','e','i','o','u']\n",
    "word = \"Milliways\"\n",
    "found = []\n",
    "for letter in word:\n",
    "    if letter in vowels:\n",
    "        if letter not in found:\n",
    "            found.append(letter)\n",
    "for vowel in found:\n",
    "    print(vowel)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "85906cf4",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on list object:\n",
      "\n",
      "class list(object)\n",
      " |  list(iterable=(), /)\n",
      " |  \n",
      " |  Built-in mutable sequence.\n",
      " |  \n",
      " |  If no argument is given, the constructor creates a new empty list.\n",
      " |  The argument must be an iterable if specified.\n",
      " |  \n",
      " |  Methods defined here:\n",
      " |  \n",
      " |  __add__(self, value, /)\n",
      " |      Return self+value.\n",
      " |  \n",
      " |  __contains__(self, key, /)\n",
      " |      Return key in self.\n",
      " |  \n",
      " |  __delitem__(self, key, /)\n",
      " |      Delete self[key].\n",
      " |  \n",
      " |  __eq__(self, value, /)\n",
      " |      Return self==value.\n",
      " |  \n",
      " |  __ge__(self, value, /)\n",
      " |      Return self>=value.\n",
      " |  \n",
      " |  __getattribute__(self, name, /)\n",
      " |      Return getattr(self, name).\n",
      " |  \n",
      " |  __getitem__(...)\n",
      " |      x.__getitem__(y) <==> x[y]\n",
      " |  \n",
      " |  __gt__(self, value, /)\n",
      " |      Return self>value.\n",
      " |  \n",
      " |  __iadd__(self, value, /)\n",
      " |      Implement self+=value.\n",
      " |  \n",
      " |  __imul__(self, value, /)\n",
      " |      Implement self*=value.\n",
      " |  \n",
      " |  __init__(self, /, *args, **kwargs)\n",
      " |      Initialize self.  See help(type(self)) for accurate signature.\n",
      " |  \n",
      " |  __iter__(self, /)\n",
      " |      Implement iter(self).\n",
      " |  \n",
      " |  __le__(self, value, /)\n",
      " |      Return self<=value.\n",
      " |  \n",
      " |  __len__(self, /)\n",
      " |      Return len(self).\n",
      " |  \n",
      " |  __lt__(self, value, /)\n",
      " |      Return self<value.\n",
      " |  \n",
      " |  __mul__(self, value, /)\n",
      " |      Return self*value.\n",
      " |  \n",
      " |  __ne__(self, value, /)\n",
      " |      Return self!=value.\n",
      " |  \n",
      " |  __repr__(self, /)\n",
      " |      Return repr(self).\n",
      " |  \n",
      " |  __reversed__(self, /)\n",
      " |      Return a reverse iterator over the list.\n",
      " |  \n",
      " |  __rmul__(self, value, /)\n",
      " |      Return value*self.\n",
      " |  \n",
      " |  __setitem__(self, key, value, /)\n",
      " |      Set self[key] to value.\n",
      " |  \n",
      " |  __sizeof__(self, /)\n",
      " |      Return the size of the list in memory, in bytes.\n",
      " |  \n",
      " |  append(self, object, /)\n",
      " |      Append object to the end of the list.\n",
      " |  \n",
      " |  clear(self, /)\n",
      " |      Remove all items from list.\n",
      " |  \n",
      " |  copy(self, /)\n",
      " |      Return a shallow copy of the list.\n",
      " |  \n",
      " |  count(self, value, /)\n",
      " |      Return number of occurrences of value.\n",
      " |  \n",
      " |  extend(self, iterable, /)\n",
      " |      Extend list by appending elements from the iterable.\n",
      " |  \n",
      " |  index(self, value, start=0, stop=9223372036854775807, /)\n",
      " |      Return first index of value.\n",
      " |      \n",
      " |      Raises ValueError if the value is not present.\n",
      " |  \n",
      " |  insert(self, index, object, /)\n",
      " |      Insert object before index.\n",
      " |  \n",
      " |  pop(self, index=-1, /)\n",
      " |      Remove and return item at index (default last).\n",
      " |      \n",
      " |      Raises IndexError if list is empty or index is out of range.\n",
      " |  \n",
      " |  remove(self, value, /)\n",
      " |      Remove first occurrence of value.\n",
      " |      \n",
      " |      Raises ValueError if the value is not present.\n",
      " |  \n",
      " |  reverse(self, /)\n",
      " |      Reverse *IN PLACE*.\n",
      " |  \n",
      " |  sort(self, /, *, key=None, reverse=False)\n",
      " |      Sort the list in ascending order and return None.\n",
      " |      \n",
      " |      The sort is in-place (i.e. the list itself is modified) and stable (i.e. the\n",
      " |      order of two equal elements is maintained).\n",
      " |      \n",
      " |      If a key function is given, apply it once to each list item and sort them,\n",
      " |      ascending or descending, according to their function values.\n",
      " |      \n",
      " |      The reverse flag can be set to sort in descending order.\n",
      " |  \n",
      " |  ----------------------------------------------------------------------\n",
      " |  Static methods defined here:\n",
      " |  \n",
      " |  __new__(*args, **kwargs) from builtins.type\n",
      " |      Create and return a new object.  See help(type) for accurate signature.\n",
      " |  \n",
      " |  ----------------------------------------------------------------------\n",
      " |  Data and other attributes defined here:\n",
      " |  \n",
      " |  __hash__ = None\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(vowels)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "2f5be9f4",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "2\n",
      "3\n"
     ]
    }
   ],
   "source": [
    "for i in [1,2,3]:\n",
    "     print(i)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4107c55b",
   "metadata": {},
   "source": [
    "> list的查询（切片）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "f19c1af0",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['Mike', 'Mary', 'Jan', 'Jack']\n",
      "Mike Jan\n",
      "['Mary', 'Jan']\n",
      "Jack\n",
      "['Mary', 'Jan']\n",
      "['Jan', 'Jack']\n",
      "['Mike', 'Mary']\n"
     ]
    }
   ],
   "source": [
    "#Zhichao\n",
    "\n",
    "names = [\"Mike\",\"Mary\",\"Jan\",\"Jack\"]\n",
    "\n",
    "print(names)\n",
    "print(names[0],names[2]) #取出某一个值\n",
    "print(names[1:3]) #切片 取出中间一些连续的值（还是列表）\n",
    "#思考：如果列表有几千个值，几万个值，那么想取出最后一个值怎么办？\n",
    "print(names[-1]) #切片 取出最后一个值\n",
    "print(names[-3:-1]) #切片 从后往前取出一些值（还是列表），思考为什么不是[-1:-3]?\n",
    "print(names[-2:]) #切片 取到最后一个值\n",
    "print(names[:2]) #切片 同上，即“0”可以省略"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "56bfcc44",
   "metadata": {},
   "source": [
    "# ②list 增、删、改\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "b3b3b35e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['Mike', 'Mary', 'Jan', 'Jack']\n",
      "['Mike', 'Mary', 'Jan', 'Jack', 'Alex']\n",
      "['Mike', 'Dan', 'Mary', 'Jan', 'Jack', 'Alex']\n",
      "['Mike', 'Dan', 'Mary', 'Zhichao', 'Jack', 'Alex']\n",
      "['Mike', 'Dan', 'Mary', 'Jack', 'Alex']\n",
      "['Mike', 'Mary', 'Jack', 'Alex']\n",
      "['Mike', 'Mary', 'Jack']\n",
      "['Mike', 'Jack']\n"
     ]
    }
   ],
   "source": [
    "#Zhichao\n",
    "\n",
    "names = [\"Mike\",\"Mary\",\"Jan\",\"Jack\"]\n",
    "\n",
    "print(names)\n",
    "names.append(\"Alex\") #list增：append增加数据，观察增加的位置。\n",
    "print(names)\n",
    "names.insert(1,\"Dan\") #list增：insert指定位置增加数据\n",
    "print(names)\n",
    "names[3] = \"Zhichao\" #list改：直接找到列表中某个值，然后赋新值\n",
    "print(names)\n",
    "names.remove(\"Zhichao\") #list删：remove指定某个数据进行删除\n",
    "print(names)\n",
    "del names[1] #list删： del指定[x]的某个数据位置进行删除\n",
    "print(names)\n",
    "names.pop() #list删：Remove and return item at index (default last) 不指定默认删除最后一个值\n",
    "print(names)\n",
    "names.pop(1) #lsit删：如果加上指定位置，names.pop(1)<==> del names[1]\n",
    "print(names)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "f24cea3e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Don't panic!\n",
      "['D', 'o', 'n', \"'\", 't', ' ', 'p', 'a', 'n', 'i', 'c', '!']\n"
     ]
    }
   ],
   "source": [
    "phrase = \"Don't panic!\"\n",
    "plist = list(phrase)\n",
    "print(phrase)\n",
    "print(plist)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "a4910f69",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on class list in module builtins:\n",
      "\n",
      "class list(object)\n",
      " |  list(iterable=(), /)\n",
      " |  \n",
      " |  Built-in mutable sequence.\n",
      " |  \n",
      " |  If no argument is given, the constructor creates a new empty list.\n",
      " |  The argument must be an iterable if specified.\n",
      " |  \n",
      " |  Methods defined here:\n",
      " |  \n",
      " |  __add__(self, value, /)\n",
      " |      Return self+value.\n",
      " |  \n",
      " |  __contains__(self, key, /)\n",
      " |      Return key in self.\n",
      " |  \n",
      " |  __delitem__(self, key, /)\n",
      " |      Delete self[key].\n",
      " |  \n",
      " |  __eq__(self, value, /)\n",
      " |      Return self==value.\n",
      " |  \n",
      " |  __ge__(self, value, /)\n",
      " |      Return self>=value.\n",
      " |  \n",
      " |  __getattribute__(self, name, /)\n",
      " |      Return getattr(self, name).\n",
      " |  \n",
      " |  __getitem__(...)\n",
      " |      x.__getitem__(y) <==> x[y]\n",
      " |  \n",
      " |  __gt__(self, value, /)\n",
      " |      Return self>value.\n",
      " |  \n",
      " |  __iadd__(self, value, /)\n",
      " |      Implement self+=value.\n",
      " |  \n",
      " |  __imul__(self, value, /)\n",
      " |      Implement self*=value.\n",
      " |  \n",
      " |  __init__(self, /, *args, **kwargs)\n",
      " |      Initialize self.  See help(type(self)) for accurate signature.\n",
      " |  \n",
      " |  __iter__(self, /)\n",
      " |      Implement iter(self).\n",
      " |  \n",
      " |  __le__(self, value, /)\n",
      " |      Return self<=value.\n",
      " |  \n",
      " |  __len__(self, /)\n",
      " |      Return len(self).\n",
      " |  \n",
      " |  __lt__(self, value, /)\n",
      " |      Return self<value.\n",
      " |  \n",
      " |  __mul__(self, value, /)\n",
      " |      Return self*value.\n",
      " |  \n",
      " |  __ne__(self, value, /)\n",
      " |      Return self!=value.\n",
      " |  \n",
      " |  __repr__(self, /)\n",
      " |      Return repr(self).\n",
      " |  \n",
      " |  __reversed__(self, /)\n",
      " |      Return a reverse iterator over the list.\n",
      " |  \n",
      " |  __rmul__(self, value, /)\n",
      " |      Return value*self.\n",
      " |  \n",
      " |  __setitem__(self, key, value, /)\n",
      " |      Set self[key] to value.\n",
      " |  \n",
      " |  __sizeof__(self, /)\n",
      " |      Return the size of the list in memory, in bytes.\n",
      " |  \n",
      " |  append(self, object, /)\n",
      " |      Append object to the end of the list.\n",
      " |  \n",
      " |  clear(self, /)\n",
      " |      Remove all items from list.\n",
      " |  \n",
      " |  copy(self, /)\n",
      " |      Return a shallow copy of the list.\n",
      " |  \n",
      " |  count(self, value, /)\n",
      " |      Return number of occurrences of value.\n",
      " |  \n",
      " |  extend(self, iterable, /)\n",
      " |      Extend list by appending elements from the iterable.\n",
      " |  \n",
      " |  index(self, value, start=0, stop=9223372036854775807, /)\n",
      " |      Return first index of value.\n",
      " |      \n",
      " |      Raises ValueError if the value is not present.\n",
      " |  \n",
      " |  insert(self, index, object, /)\n",
      " |      Insert object before index.\n",
      " |  \n",
      " |  pop(self, index=-1, /)\n",
      " |      Remove and return item at index (default last).\n",
      " |      \n",
      " |      Raises IndexError if list is empty or index is out of range.\n",
      " |  \n",
      " |  remove(self, value, /)\n",
      " |      Remove first occurrence of value.\n",
      " |      \n",
      " |      Raises ValueError if the value is not present.\n",
      " |  \n",
      " |  reverse(self, /)\n",
      " |      Reverse *IN PLACE*.\n",
      " |  \n",
      " |  sort(self, /, *, key=None, reverse=False)\n",
      " |      Sort the list in ascending order and return None.\n",
      " |      \n",
      " |      The sort is in-place (i.e. the list itself is modified) and stable (i.e. the\n",
      " |      order of two equal elements is maintained).\n",
      " |      \n",
      " |      If a key function is given, apply it once to each list item and sort them,\n",
      " |      ascending or descending, according to their function values.\n",
      " |      \n",
      " |      The reverse flag can be set to sort in descending order.\n",
      " |  \n",
      " |  ----------------------------------------------------------------------\n",
      " |  Static methods defined here:\n",
      " |  \n",
      " |  __new__(*args, **kwargs) from builtins.type\n",
      " |      Create and return a new object.  See help(type) for accurate signature.\n",
      " |  \n",
      " |  ----------------------------------------------------------------------\n",
      " |  Data and other attributes defined here:\n",
      " |  \n",
      " |  __hash__ = None\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b2ecade2",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "75247a32",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
